Combination Sum
Medium
Question
Given a list of unique positive integers and a target, find all unique combinations in the list where its sum is equal to the target.
Input: nums = [2, 3, 5], target = 8
Output: [[2, 2, 2, 2], [2, 3, 3], [3, 5]]
There are 3 unique combinations that sum up to 8.
- 2 + 2 + 2 + 2
- 2 + 3 + 3
- 3 + 5
Input: nums = [2, 4, 6, 8], target = 8
Output: [[2, 2, 2, 2], [2, 2, 4], [2, 6], [4, 4], [8]]
There are 5 unique combinations that sum up to 8.
- 2 + 2 + 2 + 2
- 2 + 2 + 4
- 2 + 6
- 4 + 4
- 8
Input: nums = [2, 4, 6, 8], target = 9
Output: []
There are no combinations that sum up to 9.
Clarify the problem
What are some questions you'd ask an interviewer?
Understand the problem
How many unique combinations are there when nums = [2, 3, 7] and target = 7?
1
2
3
4
All test cases pass! 🎉
Time limit exceeded
InputExpected OutputActual Output
Standard OutputScroll down...
Login or signup to save your code.
Uh oh... looks like you don't yet have access.
Not sure what this unlocks? Check out a free pattern section.